package org.fin.framework.ioc.beans;

import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.util.ArrayList;
import java.util.List;

public class DependencyDefinition {

  private List<String> injectBeanIds;

  private Member injectTarget;

  public Member getInjectTarget() {
    return injectTarget;
  }

  public void setInjectTarget(Member injectTarget) {
    this.injectTarget = injectTarget;
  }

  public List<String> getInjectBeanIds() {
    synchronized (this) {
      if (injectBeanIds == null) {
        if (injectTarget != null && injectTarget.getClass() == Field.class) {
          injectBeanIds = new ArrayList<>(1);
        }else {
          injectBeanIds = new ArrayList<>(4);
        }
      }
    }
    return injectBeanIds;
  }

  public void addInjectBeanId(String injectBeanId) {
    if (this.injectBeanIds == null) {
      this.injectBeanIds = getInjectBeanIds();
    }
    this.injectBeanIds.add(injectBeanId);
  }

  @Override
  public String toString() {
    return "DependencyDefinition{" +
        "injectBeanIds='" + injectBeanIds + '\'' +
        ", injectTarget=" + injectTarget +
        '}';
  }
}
